var com = "COM4";
/**
 * 读卡
 */
function readCard() {
	var result = myact.ReadCardSN("COM4"); //读IC卡 ReadCardSN是上面的方法
	if (!/^[0-9]+$/.test(result)) {
		alert("读卡失败 Error："+result);
		return;
	}
	document.getElementById("cardSn").value = result;
	//var cardNo = result.substring(4,10);
	//var resultCode = myact.WriteCard(com, cardNo);
	//for ( var i = 3; i < a.length; i++) {
	//	b = b + a.charAt(i);
	//}
	//if(resultCode == 0){
	//	document.getElementById("cardNo").value = cardNo;
	//}else{
	//	alert("写入失败！")
	//}
}

/**
 * 增加会员信息
 */
function doAdd() {
	var cardSn = document.getElementById("cardSn").value;
	if (isNull(cardSn)) {
		alert("请获取人脸通卡号！");
		return false;
	}
	var cardNo = document.getElementById("cardNo").value;
	if (isNull(cardNo)) {
		alert("请获取一卡通卡号！");
		return false;
	}
	var custName = document.getElementById("custName").value;
	if (isNull(custName)) {
		alert("请输入姓名！");
		return false;
	}
	var sex = document.getElementById("sex").value;
	var typeId = document.getElementById("typeID").value;
	var numberId = document.getElementById("numberID").value;
	if (isNull(numberId)) {
		alert("证件号码不能为空！");
		return false;
	}
	var tel = document.getElementById("tel").value;
	if (isNull(tel) || !/^[0-9]+$/.test(tel)) {
		alert("电话号码不能为空或只能是数字组合！");
		return false;
	}
	//var result = myact.AddUserInfo(cardNo, cardSn, custName, sex, 2, typeId,
	//		numberId);
	//if (result == 0) {
			document.forms[0].action = "cms/customer/doAdd.do";
			document.forms[0].submit();
	//} else {
	//	alert(result);
	//}
}

function doLost(customerId, cardNo, status, key) {
	var r = confirm("确定要" + key + "!");
	if (r == true) {
		//var result = myact.ReplyUserInfo(cardNo, status);
		//if (result == 0) {
			var a = document.getElementById("queryHref");
			//指定<a>标签的href  
			a.href = "cms/customer/doLost.do?customer.customerId=" + customerId
					+ "&customer.status =" + status;
			//取消<a>标签原先的onclick事件,使<a>标签点击后通过href跳转(因为无法用js跳转)^-^  
			a.setAttribute("onclick", '');
			//激发标签点击事件OVER  
			a.click("return true");
		//} else {
		//	alert("操作失败 Error:"+result);
		//	return;
		//}
	} else {
		return;
	}
}

function doUpdate() {
	var sign = 1 ;
	var cardOldNo = document.getElementById("cardOldNo").value;
	//var custOldName = document.getElementById("custOldName").value;
	var cardSn = document.getElementById("cardSn").value;
	var cardNo = document.getElementById("cardNo").value;
	var custName = document.getElementById("custName").value;
	if(cardOldNo != cardNo){
		sign = 0;
	}
	if(isNull(custName)){
		alert("请输入姓名！");
		return false;
	}
	//var result = myact.UpdateUserInfo(cardOldNo, cardNo, cardSn, custName, 2, sign);
	//if (result == 0) {
		document.forms[0].action = "cms/customer/doMod.do";
		document.forms[0].submit();
	//} else {
	//	alert("更新失败 Error:" +result);
	//}
}

function isNull(value) {
	if (value == null || value == "") {
		return true;
	}
	return false;
}

function confirmUpload(){
	var r = confirm("是否以增量方式上传人员权限！\n如果选择'取消'将重新上传所有人员的权限（需要较长的时间）。");
	if (r == true) {
		var result = myact.UpLoad("1");
		if(result == 0){
			alert("上传成功")
		}else{
			alert("上传失败 Error:" + result);
		}
	}else{
		var resultCode = myact.UpLoad("0");
		if(resultCode == 0 || resultCode =="21021"){
			alert("上传成功")
		}else{
			alert("上传失败 Error:" + resultCode);
		}
	}
}
